/**
 *  请求数据服务在此声明，页面请求接口调用此文件里的代码
 */

import { post } from '../index';
import {
	AnalysePageConfigReq,
	AnalysePageReq,
	BatchAnalyseCategoryDelReq,
	CreateAnalyseCategoryDto,
	CreateAnalysePageConfigsDto,
	CreateBiUiAnalysePageDto,
	DBTableColumnReq,
	// DBTableReq,
	InitTenantReq,
	PublishAnalysePageConfigsDto,
	ReportPageReq,
	UpdateAnalyseCategoryDto,
	UpdateAnalysePageConfigsDto,
	UpdateBiUiAnalysePageDto,
	updateShareParams,
	getShareConfigParams,
	getDecryptInfo,
	validateReportPwdParams,
	homePageParams,
	saveResourcePermissionParams,
	selectOrgPosWithEmpTreeParams,
	delChartComponentReq,
	getChartComponentReq,
	batchDelAnalyseCategoriesReq,
	getCategoryTreeReq
} from './type';
import { commonOutput } from 'src/services/DataManage/type';

export const saveChartComponent = ( params: ReportPageReq ): Promise<commonOutput> => {
	return post( '/analyseManage/saveChartComponent', params );
};
export const delChartComponent = ( params: delChartComponentReq ): Promise<commonOutput> => {
	return post( '/analyseManage/delChartComponent', params );
};
export const getChartComponent = ( params: getChartComponentReq ): Promise<commonOutput> => {
	return post( '/analyseManage/getChartComponent', params );
};

export const getCategoryTree = ( params: getCategoryTreeReq ): Promise<commonOutput> => {
	return post( '/analyseManage/getCategoryTree', params );
};

export const getInternalCategoryTree = (  ): Promise<commonOutput> => {
	return post( '/analyseManage/getInternalCategoryTree', {} );
};

export const getDefaultCategoryTree = ( params: ReportPageReq ): Promise<commonOutput> => {
	return post( '/analyseManage/getDefaultCategoryTree', params );
};
export const getCustomerCategoryTree = ( params: ReportPageReq ): Promise<commonOutput> => {
	return post( '/analyseManage/getCustomerCategoryTree', params );
};
export const createAnalyseCategory = ( params: CreateAnalyseCategoryDto ): Promise<commonOutput> => {
	return post( '/analyseManage/createAnalyseCategory', params );
};
export const updateAnalyseCategory = ( params: UpdateAnalyseCategoryDto ): Promise<commonOutput> => {
	return post( '/analyseManage/updateAnalyseCategory', params );
};
export const delAnalyseCategory = ( id: any ): Promise<commonOutput> => {
	// console.log( id );
	return post( '/analyseManage/delAnalyseCategory', { id: id } );
};
export const batchDelAnalyseCategories = ( params: batchDelAnalyseCategoriesReq ): Promise<commonOutput> => {
	// console.log( id );
	return post( '/analyseManage/batchDelAnalyseCategories', params );
};
export const initTenantAnalyse = ( params: InitTenantReq ): Promise<commonOutput> => {
	return post( '/analyseManage/initTenantAnalyse', params );
};
export const getChildAnalysePageList = ( params: AnalysePageReq ): Promise<commonOutput> => {
	return post( '/analyseManage/getChildAnalysePageList', params );
};
export const createAnalysePage = ( params: CreateBiUiAnalysePageDto ): Promise<commonOutput> => {
	return post( '/analyseManage/createAnalysePage', params );
};
export const updateAnalysePage = ( params: UpdateBiUiAnalysePageDto ): Promise<commonOutput> => {
	return post( '/analyseManage/updateAnalysePage', params );
};
export const delAnalysePage = ( id: any ): Promise<commonOutput> => {
	return post( '/analyseManage/delAnalysePage', { id: id } );
};
export const getAnalysePage = ( id: any ): Promise<commonOutput> => {
	return post( '/analyseManage/getAnalysePage', { id: id } );
};
export const getAnalysePageConfig = ( params: AnalysePageConfigReq ): Promise<commonOutput> => {
	return post( '/analyseManage/getAnalysePageConfig', params );
};

//	不需要登录
export const getPublicAnalysePageConfig = ( params: AnalysePageConfigReq ): Promise<commonOutput> => {
	return post( '/analyseManage/getPublicAnalysePageConfig', params );
};

export const createAnalysePageConfig = ( params: CreateAnalysePageConfigsDto ): Promise<commonOutput> => {
	return post( '/analyseManage/createAnalysePageConfig', params );
};
export const publishAnalysePageConfig = ( params: PublishAnalysePageConfigsDto ): Promise<commonOutput> => {
	return post( '/analyseManage/publishAnalysePageConfig', params );
};
/**
 * 查看页面配置详情列表
 * @param params
 */
export const getAnalysePageConfigList = ( params: AnalysePageConfigReq ): Promise<commonOutput> => {
	return post( '/analyseManage/getAnalysePageConfigList', params );
};
export const delAnalysePageConfig = ( id: any ): Promise<commonOutput> => {
	return post( '/analyseManage/delAnalysePageConfig', { id: id } );
};
export const updateAnalysePageConfig = ( params: UpdateAnalysePageConfigsDto ): Promise<commonOutput> => {
	return post( '/analyseManage/updateAnalysePageConfig', params );
};
export const getAllTable = ( params: any ): Promise<commonOutput> => {
	return post( '/analyseManage/getAllTable', params );
};
export const getAllColumns = ( params: DBTableColumnReq ): Promise<commonOutput> => {
	return post( '/analyseManage/getAllColumns', params );
};
export const getAnalysePageDrafts = ( params: AnalysePageReq ): Promise<commonOutput> => {
	return post( '/analyseManage/getAnalysePageDrafts', params );
};

export const batchDelAnalysePage = ( params: BatchAnalyseCategoryDelReq ): Promise<commonOutput> => {
	return post( '/analyseManage/batchDelAnalysePage', params );
};

//	公开报表不需要用户cookie
export const getComponentData = ( params: any ): Promise<commonOutput> => {
	let url = '';
	if( params.tenantCode ) {
		url = '/analyseManage/getPublicComponentData';
	} else {
		url = '/analyseManage/getComponentData';
		delete params.tenantCode;
	}
	return post( url, params );
};

export const getDataTree = ( params: any ): Promise<commonOutput> => {
	return post( '/analyseManage/getDataTree', params );
};

export const saveDataTree = ( params: any ): Promise<commonOutput> => {
	return post( '/analyseManage/saveDataTree', params );
};

export const updateShareConfig = ( params: updateShareParams ): Promise<commonOutput> => {
	return post( '/analyseManage/updateShareConfig', params );
};

export const getShareConfig = ( params: getShareConfigParams ): Promise<commonOutput> => {
	return post( '/analyseManage/getShareConfig', params );
};

export const getShareUrl = ( params: getShareConfigParams ): Promise<commonOutput> => {
	return post( '/analyseManage/getShareUrl', params );
};

export const getReportInfo = ( params: getDecryptInfo ): Promise<commonOutput> => {
	return post( '/analyseManage/getReportInfo', params );
};

//	不需要登录
export const getPublicReportInfo = ( params: getDecryptInfo ): Promise<commonOutput> => {
	return post( '/analyseManage/getPublicReportInfo', params );
};

export const validateReportPwd = ( params: validateReportPwdParams ): Promise<commonOutput> => {
	return post( '/analyseManage/validateReportPwd', params );
};

export const setHomePage = ( params: homePageParams ): Promise<commonOutput> => {
	return post( '/analyseManage/setHomePage', params );
};

export const getHomePageId = ( params: any ): Promise<commonOutput> => {
	return post( '/analyseManage/getHomePageId', params );
};

export const selectOrgPosWithEmpTree = ( params: selectOrgPosWithEmpTreeParams ): Promise<commonOutput> => {
	return post( '/analyseManage/selectOrgPosWithEmpTree', params );
};

export const saveResourcePermission = ( params: saveResourcePermissionParams ): Promise<commonOutput> => {
	return post( '/analyseManage/saveResourcePermission', params );
};

export const subscribeGet = ( pageId: String ): Promise<commonOutput> => {
	return post( '/analyseManage/subscribeGet', { pageId } );
};

export const subscribeSave = ( params: any ): Promise<commonOutput> => {
	return post( '/analyseManage/subscribeSave', params );
};

export const subscribeLog = ( params: any ): Promise<commonOutput> => {
	return post( '/analyseManage/subscribeLog', params );
};

export const deleteFile = ( params: any ): Promise<commonOutput> => {
	return post( '/uploadfile/deletefile', params );
};

export const getResourcePermission = ( params: any ): Promise<commonOutput> => {
	return post( '/analyseManage/getResourcePermission', params );
};

// 保存或者更新层级
export const saveOrUpdateFolder = ( params: any ): Promise<commonOutput> => {
	return post( '/analyseManage/saveOrUpdateFolder', params );
};

export const getDataPermission = ( params: any ): Promise<commonOutput> => {
	return post( '/analyseManage/getDataPermission', params );
};

export const copyDeloittePage = ( params: any ): Promise<commonOutput> => {
	return post( '/analyseManage/copyDeloittePage', params );
};

export const getDataSetByCode = ( params: any ): Promise<commonOutput> => {
	return post( '/analyseManage/getDataSetByCode', params );
};

export const replaceDataSet = ( params: any ): Promise<commonOutput> => {
	return post( '/analyseManage/replaceDataSet', params );
};
export const getPagePermissionByCode = ( params: any ): Promise<commonOutput> => {
	return post( '/analyseManage/getPagePermissionByCode', params );
};

export const getPageDataPermissionByCode = ( params: any ): Promise<commonOutput> => {
	return post( '/analyseManage/getPageDataPermissionByCode', params );
};
